package com.caseprocessing.model;

import java.util.List;

/**
 * 页面数据模型
 */
public class Page {
    
    private int pageId;
    private String imageUrl;
    private Dimensions dimensions;
    private PageMetadata pageMetadata;
    private List<TextBlock> textBlocks;
    private List<LayoutElement> layoutElements;
    
    public Page() {}
    
    public Page(int pageId, String imageUrl) {
        this.pageId = pageId;
        this.imageUrl = imageUrl;
    }
    
    // Getters and Setters
    public int getPageId() { return pageId; }
    public void setPageId(int pageId) { this.pageId = pageId; }
    
    public String getImageUrl() { return imageUrl; }
    public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; }
    
    public Dimensions getDimensions() { return dimensions; }
    public void setDimensions(Dimensions dimensions) { this.dimensions = dimensions; }
    
    public PageMetadata getPageMetadata() { return pageMetadata; }
    public void setPageMetadata(PageMetadata pageMetadata) { this.pageMetadata = pageMetadata; }
    
    public List<TextBlock> getTextBlocks() { return textBlocks; }
    public void setTextBlocks(List<TextBlock> textBlocks) { this.textBlocks = textBlocks; }
    
    public List<LayoutElement> getLayoutElements() { return layoutElements; }
    public void setLayoutElements(List<LayoutElement> layoutElements) { this.layoutElements = layoutElements; }
    
    /**
     * 获取页面全部文本内容
     */
    public String getFullText() {
        if (textBlocks == null || textBlocks.isEmpty()) {
            return "";
        }
        
        StringBuilder fullText = new StringBuilder();
        for (TextBlock block : textBlocks) {
            fullText.append(block.getText()).append(" ");
        }
        return fullText.toString().trim();
    }
    
    /**
     * 检查页面是否包含指定类型的布局元素
     */
    public boolean hasLayoutElement(String elementType) {
        return layoutElements != null && 
               layoutElements.stream().anyMatch(element -> elementType.equals(element.getType()));
    }
    
    /**
     * 获取指定类型的布局元素
     */
    public List<LayoutElement> getLayoutElementsByType(String elementType) {
        if (layoutElements == null) {
            return List.of();
        }
        return layoutElements.stream()
                .filter(element -> elementType.equals(element.getType()))
                .toList();
    }
}